#include "mainwindow.h"
#include"widget.h"
#include"TestFrame.h"
#include"TestLabel.h"
#include"TestButtom.h"
#include"TestLineEdit.h"
#include"TestAction.h"
#include"TestLayout.h"
#include"TestTextEdit.h"
#include"TestRadioButton.h"
#include"TestCheckBox.h"
#include"TestSpinBox.h"
#include"TestComboBox.h"

#include <QApplication>
#include<QDebug>
void test_qstring();

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    //w.show();
    test_qstring();
    TestFrame test_frame;
    //test_frame.show();
    TestLabel test_label;
    //test_label.show();

    TestButtom test_buttom;
    //test_buttom.show();

    TestLineEdit test_lineedit;
    //test_lineedit.show();

    TestAction test_action;
    //test_action.show();

    TestLayout test_layout;
    //test_layout.show();

    TestTextEdit Test_TextEdit;
    //Test_TextEdit.show();

    TestRadioButton Test_RadioButton;
    //Test_RadioButton.show();

    TestCheckBox Test_CheckBox;
    //Test_CheckBox.show();

    TestSpinBox Test_SpinBox;
    //Test_SpinBox.show();

    TestComboBox Test_ComboBox;
    Test_ComboBox.show();

    return a.exec();
}

void test_qstring()
{
    /*******************
     * QString
     * ******************/
    //1 构造，追加，拼接
    QString str1("welcome");
    str1.append(" world!");
    str1= str1 + " QT";
    str1= "hi,"+ str1;
    str1.prepend("pre ");
    qDebug()<<str1;

    //2 QString::sprintf() 组合
    //QString::sprintf()  //会清除原本的内容
    QString str2;
    str2.sprintf("%s","Welcome");//str="Welcome"
    str2.sprintf("%s","to you!");//str="to you!"
    str2.sprintf("%s %s","Welcome","to you!");//str=”Welcome to you!"
    qDebug()<<str2;

    //3 QString::sprintf().arg() 组合
    QString str3;
    str3=QString("%1 was born in %2.").arg("John").arg(1998);	//str="John was born in1998."
    qDebug()<<str3;

    //4 insert插入
    QString str4 ="word";
    str4.insert(3,"1");//string ==“world”
    qDebug()<<str4;

    //5 indexOf / lastIndexOf 首次出现 /最后一次出现 的位置
    QString str5="D:\\work_space\\project\\test_qstring";
    QString str5_2="\\";
    qDebug()<<"first \\ in:"<<str5.indexOf(str5_2);
    qDebug()<<"last \\ in:"<<str5.lastIndexOf(str5_2);

    //6 trimmed()去除两端空格
    QString str6="lots\t of\nwhitespace\r\n";
    qDebug()<<str6;
    str6 =str6.trimmed();
    qDebug()<<str6;
    str6="lots\t of\nwhitespace\r\n";
    str6 =str6.simplified();
    qDebug()<<str6;

    //7 split()字符串切片
    QString str7 ="a,b,c";
    QStringList list_split =str7.split(",");	//list:["a","b","c"]
    qDebug()<<list_split;
    str7 ="D:\\work_space\\project\\test_qstring";
    list_split =str7.split("\\");
    qDebug()<<list_split;

    //mid(),left(),right()
    QString str8 ="hello";
    QString str8_2 = str8.mid(4, 5);
    qDebug()<<str8_2;
    str8 ="D:\\work_space\\project\\test_qstring";
    qDebug()<<str8.left(str8.lastIndexOf("\\"));
    qDebug()<<str8.right(str8.lastIndexOf("\\"));
}
